<template>
  <div class="login">
    <div class="box">
      <p><input type="text" placeholder="用户名" v-model.trim="user"></p>
      <p><input type="password" placeholder="请输入密码" v-model.trim="pwd"></p>
      <p><button @click="login">登录</button></p>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      user: '',
      pwd: ''
    }
  },
  methods: {
    login () {
      // 判断用户是否输入信息
      if (!this.user || !this.pwd) {
        alert('请输入用户名和密码')
      } else {
        // 登录并且设置唯一值用来判断是用户是否登录
        localStorage.setItem('token', this.user + this.pwd)
        this.$router.replace('/')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.login{
  width: 100%;
  height: 100%;
  background-image: linear-gradient(to right bottom, #00b3ff, #0055ff);
  position: relative;
}
.box{
  position: absolute;
  width: 260px;
  height: 200px;
  background: #fff;
  right: 200px;
  top: 40%;
  padding: 20px;
  border-radius: 5px;
  transform: translateY(-0%);
  p{
    width: 100%;
    height: 40px;
    margin:10px 0px;
    input{
      width: 100%;
      height: 100%;
      outline: 0;
      border-radius: 5px;
      border: 1px solid #ccc;
      padding-left: 10px;
    }
    button{
      width: 100%;
      height: 100%;
      background: #00b3ff;
      color: #fff;
      border: 0;
      border-radius: 7px;
    }
  }
}
</style>
